<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>IPC::Cmd - finding and running system commands made easy - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/IPC::Cmd">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./IPC::Cmd.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/IPC::Cmd">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/IPC::Cmd">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/IPC::Cmd">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/IPC::Cmd">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/IPC::Cmd">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/IPC::Cmd">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/IPC::Cmd">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/IPC::Cmd">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/IPC::Cmd">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/IPC::Cmd">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/IPC::Cmd">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/IPC::Cmd">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/IPC::Cmd">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/IPC::Cmd">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/IPC::Cmd">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/IPC::Cmd">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/IPC::Cmd">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/IPC::Cmd">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/IPC::Cmd">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/IPC::Cmd">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/IPC::Cmd">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/IPC::Cmd">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/IPC::Cmd">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/IPC::Cmd">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/IPC::Cmd">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/IPC::Cmd">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/IPC::Cmd">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/IPC::Cmd">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/IPC::Cmd">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/IPC::Cmd">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/IPC::Cmd">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/IPC::Cmd">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/IPC::Cmd">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/IPC::Cmd">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/IPC::Cmd">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/IPC::Cmd">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/IPC::Cmd">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/IPC::Cmd">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/IPC::Cmd">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/IPC::Cmd">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/IPC::Cmd">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/IPC::Cmd">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/IPC::Cmd">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/IPC::Cmd">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/IPC::Cmd">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/IPC::Cmd">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/IPC::Cmd">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/IPC::Cmd">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/IPC::Cmd">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/IPC::Cmd">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/IPC::Cmd">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/IPC::Cmd">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/IPC::Cmd">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/IPC::Cmd">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/IPC::Cmd">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/IPC::Cmd">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/IPC::Cmd">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/IPC::Cmd">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/IPC::Cmd">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/IPC::Cmd">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/IPC::Cmd">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/IPC::Cmd">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/IPC::Cmd">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/IPC::Cmd">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/IPC::Cmd">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/IPC::Cmd">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/IPC::Cmd">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/IPC::Cmd">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/IPC::Cmd">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/IPC::Cmd">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/IPC::Cmd">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/IPC::Cmd">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/IPC::Cmd">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/IPC::Cmd">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/IPC::Cmd">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/IPC::Cmd">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/IPC::Cmd">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/IPC::Cmd">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/IPC::Cmd">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/IPC::Cmd">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./IPC::Cmd.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/IPC::Cmd">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/IPC::Cmd">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/IPC::Cmd">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/IPC::Cmd">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/IPC::Cmd">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/IPC::Cmd">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/IPC::Cmd">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/IPC::Cmd">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/IPC::Cmd">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/IPC::Cmd">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/IPC::Cmd">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/IPC::Cmd">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/IPC::Cmd">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/IPC::Cmd">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/IPC::Cmd">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/IPC::Cmd">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/IPC::Cmd">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/IPC::Cmd">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/IPC::Cmd">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/IPC::Cmd">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/IPC::Cmd">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/IPC::Cmd">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/IPC::Cmd">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/IPC::Cmd">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/IPC::Cmd">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/IPC::Cmd">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/IPC::Cmd">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/IPC::Cmd">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/IPC::Cmd">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/IPC::Cmd">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/IPC::Cmd">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/IPC::Cmd">5.35.1</a>
          <a class="dropdown-item active" href="./IPC::Cmd.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./IPC::Cmd.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="./IPC::Cmd.html">IPC::Cmd</a>
          <div id="more">
            (<a href="./IPC::Cmd.txt">source</a>,
            <a href="https://metacpan.org/pod/IPC::Cmd">CPAN</a>)
          </div>
            <div id="moduleversion">version 1.04</div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#SYNOPSIS">SYNOPSIS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#DESCRIPTION">DESCRIPTION</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#CLASS-METHODS">CLASS METHODS</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#$ipc_run_version-=-IPC::Cmd-%3Ecan_use_ipc_run(-%5BVERBOSE%5D-)">$ipc_run_version = IPC::Cmd-&gt;can_use_ipc_run( [VERBOSE] )</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#$ipc_open3_version-=-IPC::Cmd-%3Ecan_use_ipc_open3(-%5BVERBOSE%5D-)">$ipc_open3_version = IPC::Cmd-&gt;can_use_ipc_open3( [VERBOSE] )</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#$bool-=-IPC::Cmd-%3Ecan_capture_buffer">$bool = IPC::Cmd-&gt;can_capture_buffer</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#$bool-=-IPC::Cmd-%3Ecan_use_run_forked">$bool = IPC::Cmd-&gt;can_use_run_forked</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#FUNCTIONS">FUNCTIONS</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#$path-=-can_run(-PROGRAM-);">$path = can_run( PROGRAM );</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#$ok-%7C-($ok,-$err,-$full_buf,-$stdout_buff,-$stderr_buff)-=-run(-command-=%3E-COMMAND,-%5Bverbose-=%3E-BOOL,-buffer-=%3E-%5C$SCALAR,-timeout-=%3E-DIGIT%5D-);">$ok | ($ok, $err, $full_buf, $stdout_buff, $stderr_buff) = run( command =&gt; COMMAND, [verbose =&gt; BOOL, buffer =&gt; \$SCALAR, timeout =&gt; DIGIT] );</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#$hashref-=-run_forked(-COMMAND,-%7B-child_stdin-=%3E-SCALAR,-timeout-=%3E-DIGIT,-stdout_handler-=%3E-CODEREF,-stderr_handler-=%3E-CODEREF%7D-);">$hashref = run_forked( COMMAND, { child_stdin =&gt; SCALAR, timeout =&gt; DIGIT, stdout_handler =&gt; CODEREF, stderr_handler =&gt; CODEREF} );</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#$q-=-QUOTE">$q = QUOTE</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#HOW-IT-WORKS">HOW IT WORKS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#Global-Variables">Global Variables</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#$IPC::Cmd::VERBOSE">$IPC::Cmd::VERBOSE</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#$IPC::Cmd::USE_IPC_RUN">$IPC::Cmd::USE_IPC_RUN</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#$IPC::Cmd::USE_IPC_OPEN3">$IPC::Cmd::USE_IPC_OPEN3</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#$IPC::Cmd::WARN">$IPC::Cmd::WARN</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#$IPC::Cmd::INSTANCES">$IPC::Cmd::INSTANCES</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#$IPC::Cmd::ALLOW_NULL_ARGS">$IPC::Cmd::ALLOW_NULL_ARGS</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#Caveats">Caveats</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#See-Also">See Also</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#ACKNOWLEDGEMENTS">ACKNOWLEDGEMENTS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#BUG-REPORTS">BUG REPORTS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#AUTHOR">AUTHOR</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IPC::Cmd.html#COPYRIGHT">COPYRIGHT</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="./IPC::Cmd.html#NAME">#</a>NAME</h1>

<p>IPC::Cmd - finding and running system commands made easy</p>

<h1 id="SYNOPSIS"><a class="permalink" href="./IPC::Cmd.html#SYNOPSIS">#</a>SYNOPSIS</h1>

<pre><code>use IPC::Cmd qw[can_run run run_forked];

my $full_path = can_run(&#39;wget&#39;) or warn &#39;wget is not installed!&#39;;

### commands can be arrayrefs or strings ###
my $cmd = &quot;$full_path -b theregister.co.uk&quot;;
my $cmd = [$full_path, &#39;-b&#39;, &#39;theregister.co.uk&#39;];

### in scalar context ###
my $buffer;
if( scalar run( command =&gt; $cmd,
                verbose =&gt; 0,
                buffer  =&gt; \$buffer,
                timeout =&gt; 20 )
) {
    print &quot;fetched webpage successfully: $buffer\n&quot;;
}


### in list context ###
my( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) =
        run( command =&gt; $cmd, verbose =&gt; 0 );

if( $success ) {
    print &quot;this is what the command printed:\n&quot;;
    print join &quot;&quot;, @$full_buf;
}

### run_forked example ###
my $result = run_forked(&quot;$full_path -q -O - theregister.co.uk&quot;, {&#39;timeout&#39; =&gt; 20});
if ($result-&gt;{&#39;exit_code&#39;} eq 0 &amp;&amp; !$result-&gt;{&#39;timeout&#39;}) {
    print &quot;this is what wget returned:\n&quot;;
    print $result-&gt;{&#39;stdout&#39;};
}

### check for features
print &quot;IPC::Open3 available: &quot;  . IPC::Cmd-&gt;can_use_ipc_open3;
print &quot;IPC::Run available: &quot;    . IPC::Cmd-&gt;can_use_ipc_run;
print &quot;Can capture buffer: &quot;    . IPC::Cmd-&gt;can_capture_buffer;

### don&#39;t have IPC::Cmd be verbose, ie don&#39;t print to stdout or
### stderr when running commands -- default is &#39;0&#39;
$IPC::Cmd::VERBOSE = 0;</code></pre>

<h1 id="DESCRIPTION"><a class="permalink" href="./IPC::Cmd.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>IPC::Cmd allows you to run commands platform independently, interactively if desired, but have them still work.</p>

<p>The <code>can_run</code> function can tell you if a certain binary is installed and if so where, whereas the <code>run</code> function can actually execute any of the commands you give it and give you a clear return value, as well as adhere to your verbosity settings.</p>

<h1 id="CLASS-METHODS"><a class="permalink" href="./IPC::Cmd.html#CLASS-METHODS">#</a><a id="CLASS"></a>CLASS METHODS</h1>

<h2 id="$ipc_run_version-=-IPC::Cmd-&gt;can_use_ipc_run(-[VERBOSE]-)"><a class="permalink" href="./IPC::Cmd.html#$ipc_run_version-=-IPC::Cmd-%3Ecan_use_ipc_run(-%5BVERBOSE%5D-)">#</a><a id="ipc_run_version-IPC::Cmd-can_use_ipc_run-VERBOSE"></a>$ipc_run_version = IPC::Cmd-&gt;can_use_ipc_run( [VERBOSE] )</h2>

<p>Utility function that tells you if <code>IPC::Run</code> is available. If the <code>verbose</code> flag is passed, it will print diagnostic messages if <a href="./IPC::Run.html">IPC::Run</a> can not be found or loaded.</p>

<h2 id="$ipc_open3_version-=-IPC::Cmd-&gt;can_use_ipc_open3(-[VERBOSE]-)"><a class="permalink" href="./IPC::Cmd.html#$ipc_open3_version-=-IPC::Cmd-%3Ecan_use_ipc_open3(-%5BVERBOSE%5D-)">#</a><a id="ipc_open3_version-IPC::Cmd-can_use_ipc_open3-VERBOSE"></a>$ipc_open3_version = IPC::Cmd-&gt;can_use_ipc_open3( [VERBOSE] )</h2>

<p>Utility function that tells you if <code>IPC::Open3</code> is available. If the verbose flag is passed, it will print diagnostic messages if <code>IPC::Open3</code> can not be found or loaded.</p>

<h2 id="$bool-=-IPC::Cmd-&gt;can_capture_buffer"><a class="permalink" href="./IPC::Cmd.html#$bool-=-IPC::Cmd-%3Ecan_capture_buffer">#</a><a id="bool-IPC::Cmd-can_capture_buffer"></a>$bool = IPC::Cmd-&gt;can_capture_buffer</h2>

<p>Utility function that tells you if <code>IPC::Cmd</code> is capable of capturing buffers in it&#39;s current configuration.</p>

<h2 id="$bool-=-IPC::Cmd-&gt;can_use_run_forked"><a class="permalink" href="./IPC::Cmd.html#$bool-=-IPC::Cmd-%3Ecan_use_run_forked">#</a><a id="bool-IPC::Cmd-can_use_run_forked"></a>$bool = IPC::Cmd-&gt;can_use_run_forked</h2>

<p>Utility function that tells you if <code>IPC::Cmd</code> is capable of providing <code>run_forked</code> on the current platform.</p>

<h1 id="FUNCTIONS"><a class="permalink" href="./IPC::Cmd.html#FUNCTIONS">#</a>FUNCTIONS</h1>

<h2 id="$path-=-can_run(-PROGRAM-);"><a class="permalink" href="./IPC::Cmd.html#$path-=-can_run(-PROGRAM-);">#</a><a id="path-can_run-PROGRAM"></a>$path = can_run( PROGRAM );</h2>

<p><code>can_run</code> takes only one argument: the name of a binary you wish to locate. <code>can_run</code> works much like the unix binary <code>which</code> or the bash command <code>type</code>, which scans through your path, looking for the requested binary.</p>

<p>Unlike <code>which</code> and <code>type</code>, this function is platform independent and will also work on, for example, Win32.</p>

<p>If called in a scalar context it will return the full path to the binary you asked for if it was found, or <code>undef</code> if it was not.</p>

<p>If called in a list context and the global variable <code>$INSTANCES</code> is a true value, it will return a list of the full paths to instances of the binary where found in <code>PATH</code>, or an empty list if it was not found.</p>

<h2 id="$ok-|-($ok,-$err,-$full_buf,-$stdout_buff,-$stderr_buff)-=-run(-command-=&gt;-COMMAND,-[verbose-=&gt;-BOOL,-buffer-=&gt;-\$SCALAR,-timeout-=&gt;-DIGIT]-);"><a class="permalink" href="./IPC::Cmd.html#$ok-%7C-($ok,-$err,-$full_buf,-$stdout_buff,-$stderr_buff)-=-run(-command-=%3E-COMMAND,-%5Bverbose-=%3E-BOOL,-buffer-=%3E-%5C$SCALAR,-timeout-=%3E-DIGIT%5D-);">#</a><a id="ok-ok-err-full_buf-stdout_buff-stderr_buff-run-command-COMMAND-verbose-BOOL-buffer-SCALAR-timeout-DIGIT"></a>$ok | ($ok, $err, $full_buf, $stdout_buff, $stderr_buff) = run( command =&gt; COMMAND, [verbose =&gt; BOOL, buffer =&gt; \$SCALAR, timeout =&gt; DIGIT] );</h2>

<p><code>run</code> takes 4 arguments:</p>

<dl>

<dt id="command"><a class="permalink" href="./IPC::Cmd.html#command">#</a>command</dt>
<dd>

<p>This is the command to execute. It may be either a string or an array reference. This is a required argument.</p>

<p>See <a href="./IPC::Cmd.html#Caveats">&quot;Caveats&quot;</a> for remarks on how commands are parsed and their limitations.</p>

</dd>
<dt id="verbose"><a class="permalink" href="./IPC::Cmd.html#verbose">#</a>verbose</dt>
<dd>

<p>This controls whether all output of a command should also be printed to STDOUT/STDERR or should only be trapped in buffers (NOTE: buffers require <a href="./IPC::Run.html">IPC::Run</a> to be installed, or your system able to work with <a href="./IPC::Open3.html">IPC::Open3</a>).</p>

<p>It will default to the global setting of <code>$IPC::Cmd::VERBOSE</code>, which by default is 0.</p>

</dd>
<dt id="buffer"><a class="permalink" href="./IPC::Cmd.html#buffer">#</a>buffer</dt>
<dd>

<p>This will hold all the output of a command. It needs to be a reference to a scalar. Note that this will hold both the STDOUT and STDERR messages, and you have no way of telling which is which. If you require this distinction, run the <code>run</code> command in list context and inspect the individual buffers.</p>

<p>Of course, this requires that the underlying call supports buffers. See the note on buffers above.</p>

</dd>
<dt id="timeout"><a class="permalink" href="./IPC::Cmd.html#timeout">#</a>timeout</dt>
<dd>

<p>Sets the maximum time the command is allowed to run before aborting, using the built-in <code>alarm()</code> call. If the timeout is triggered, the <code>errorcode</code> in the return value will be set to an object of the <code>IPC::Cmd::TimeOut</code> class. See the <a href="./IPC::Cmd.html#error-message">&quot;error message&quot;</a> section below for details.</p>

<p>Defaults to <code>0</code>, meaning no timeout is set.</p>

</dd>
</dl>

<p><code>run</code> will return a simple <code>true</code> or <code>false</code> when called in scalar context. In list context, you will be returned a list of the following items:</p>

<dl>

<dt id="success"><a class="permalink" href="./IPC::Cmd.html#success">#</a>success</dt>
<dd>

<p>A simple boolean indicating if the command executed without errors or not.</p>

</dd>
<dt id="error-message"><a class="permalink" href="./IPC::Cmd.html#error-message">#</a><a id="error"></a>error message</dt>
<dd>

<p>If the first element of the return value (<code>success</code>) was 0, then some error occurred. This second element is the error message the command you requested exited with, if available. This is generally a pretty printed value of <code>$?</code> or <code>$@</code>. See <code>perldoc perlvar</code> for details on what they can contain. If the error was a timeout, the <code>error message</code> will be prefixed with the string <code>IPC::Cmd::TimeOut</code>, the timeout class.</p>

</dd>
<dt id="full_buffer"><a class="permalink" href="./IPC::Cmd.html#full_buffer">#</a>full_buffer</dt>
<dd>

<p>This is an array reference containing all the output the command generated. Note that buffers are only available if you have <a href="./IPC::Run.html">IPC::Run</a> installed, or if your system is able to work with <a href="./IPC::Open3.html">IPC::Open3</a> -- see below). Otherwise, this element will be <code>undef</code>.</p>

</dd>
<dt id="out_buffer"><a class="permalink" href="./IPC::Cmd.html#out_buffer">#</a>out_buffer</dt>
<dd>

<p>This is an array reference containing all the output sent to STDOUT the command generated. The notes from <a href="./IPC::Cmd.html#full_buffer">&quot;full_buffer&quot;</a> apply.</p>

</dd>
<dt id="error_buffer"><a class="permalink" href="./IPC::Cmd.html#error_buffer">#</a>error_buffer</dt>
<dd>

<p>This is an arrayreference containing all the output sent to STDERR the command generated. The notes from <a href="./IPC::Cmd.html#full_buffer">&quot;full_buffer&quot;</a> apply.</p>

</dd>
</dl>

<p>See the <a href="./IPC::Cmd.html#HOW-IT-WORKS">&quot;HOW IT WORKS&quot;</a> section below to see how <code>IPC::Cmd</code> decides what modules or function calls to use when issuing a command.</p>

<h2 id="$hashref-=-run_forked(-COMMAND,-{-child_stdin-=&gt;-SCALAR,-timeout-=&gt;-DIGIT,-stdout_handler-=&gt;-CODEREF,-stderr_handler-=&gt;-CODEREF}-);"><a class="permalink" href="./IPC::Cmd.html#$hashref-=-run_forked(-COMMAND,-%7B-child_stdin-=%3E-SCALAR,-timeout-=%3E-DIGIT,-stdout_handler-=%3E-CODEREF,-stderr_handler-=%3E-CODEREF%7D-);">#</a><a id="hashref-run_forked-COMMAND-child_stdin-SCALAR-timeout-DIGIT-stdout_handler-CODEREF-stderr_handler-CODEREF"></a>$hashref = run_forked( COMMAND, { child_stdin =&gt; SCALAR, timeout =&gt; DIGIT, stdout_handler =&gt; CODEREF, stderr_handler =&gt; CODEREF} );</h2>

<p><code>run_forked</code> is used to execute some program or a coderef, optionally feed it with some input, get its return code and output (both stdout and stderr into separate buffers). In addition, it allows to terminate the program if it takes too long to finish.</p>

<p>The important and distinguishing feature of run_forked is execution timeout which at first seems to be quite a simple task but if you think that the program which you&#39;re spawning might spawn some children itself (which in their turn could do the same and so on) it turns out to be not a simple issue.</p>

<p><code>run_forked</code> is designed to survive and successfully terminate almost any long running task, even a fork bomb in case your system has the resources to survive during given timeout.</p>

<p>This is achieved by creating separate watchdog process which spawns the specified program in a separate process session and supervises it: optionally feeds it with input, stores its exit code, stdout and stderr, terminates it in case it runs longer than specified.</p>

<p>Invocation requires the command to be executed or a coderef and optionally a hashref of options:</p>

<dl>

<dt id="timeout1"><a class="permalink" href="./IPC::Cmd.html#timeout1">#</a><code>timeout</code></dt>
<dd>

<p>Specify in seconds how long to run the command before it is killed with SIG_KILL (9), which effectively terminates it and all of its children (direct or indirect).</p>

</dd>
<dt id="child_stdin"><a class="permalink" href="./IPC::Cmd.html#child_stdin">#</a><code>child_stdin</code></dt>
<dd>

<p>Specify some text that will be passed into the <code>STDIN</code> of the executed program.</p>

</dd>
<dt id="stdout_handler"><a class="permalink" href="./IPC::Cmd.html#stdout_handler">#</a><code>stdout_handler</code></dt>
<dd>

<p>Coderef of a subroutine to call when a portion of data is received on STDOUT from the executing program.</p>

</dd>
<dt id="stderr_handler"><a class="permalink" href="./IPC::Cmd.html#stderr_handler">#</a><code>stderr_handler</code></dt>
<dd>

<p>Coderef of a subroutine to call when a portion of data is received on STDERR from the executing program.</p>

</dd>
<dt id="wait_loop_callback"><a class="permalink" href="./IPC::Cmd.html#wait_loop_callback">#</a><code>wait_loop_callback</code></dt>
<dd>

<p>Coderef of a subroutine to call inside of the main waiting loop (while <code>run_forked</code> waits for the external to finish or fail). It is useful to stop running external process before it ends by itself, e.g.</p>

<pre><code>  my $r = run_forked(&quot;some external command&quot;, {
	  &#39;wait_loop_callback&#39; =&gt; sub {
          if (condition) {
              kill(1, $$);
          }
	  },
	  &#39;terminate_on_signal&#39; =&gt; &#39;HUP&#39;,
	  });</code></pre>

<p>Combined with <code>stdout_handler</code> and <code>stderr_handler</code> allows terminating external command based on its output. Could also be used as a timer without engaging with <a href="https://perldoc.perl.org/5.35.0/alarm">alarm</a> (signals).</p>

<p>Remember that this code could be called every millisecond (depending on the output which external command generates), so try to make it as lightweight as possible.</p>

</dd>
<dt id="discard_output"><a class="permalink" href="./IPC::Cmd.html#discard_output">#</a><code>discard_output</code></dt>
<dd>

<p>Discards the buffering of the standard output and standard errors for return by run_forked(). With this option you have to use the std*_handlers to read what the command outputs. Useful for commands that send a lot of output.</p>

</dd>
<dt id="terminate_on_parent_sudden_death"><a class="permalink" href="./IPC::Cmd.html#terminate_on_parent_sudden_death">#</a><code>terminate_on_parent_sudden_death</code></dt>
<dd>

<p>Enable this option if you wish all spawned processes to be killed if the initially spawned process (the parent) is killed or dies without waiting for child processes.</p>

</dd>
</dl>

<p><code>run_forked</code> will return a HASHREF with the following keys:</p>

<dl>

<dt id="exit_code"><a class="permalink" href="./IPC::Cmd.html#exit_code">#</a><code>exit_code</code></dt>
<dd>

<p>The exit code of the executed program.</p>

</dd>
<dt id="timeout2"><a class="permalink" href="./IPC::Cmd.html#timeout2">#</a><code>timeout</code></dt>
<dd>

<p>The number of seconds the program ran for before being terminated, or 0 if no timeout occurred.</p>

</dd>
<dt id="stdout"><a class="permalink" href="./IPC::Cmd.html#stdout">#</a><code>stdout</code></dt>
<dd>

<p>Holds the standard output of the executed command (or empty string if there was no STDOUT output or if <code>discard_output</code> was used; it&#39;s always defined!)</p>

</dd>
<dt id="stderr"><a class="permalink" href="./IPC::Cmd.html#stderr">#</a><code>stderr</code></dt>
<dd>

<p>Holds the standard error of the executed command (or empty string if there was no STDERR output or if <code>discard_output</code> was used; it&#39;s always defined!)</p>

</dd>
<dt id="merged"><a class="permalink" href="./IPC::Cmd.html#merged">#</a><code>merged</code></dt>
<dd>

<p>Holds the standard output and error of the executed command merged into one stream (or empty string if there was no output at all or if <code>discard_output</code> was used; it&#39;s always defined!)</p>

</dd>
<dt id="err_msg"><a class="permalink" href="./IPC::Cmd.html#err_msg">#</a><code>err_msg</code></dt>
<dd>

<p>Holds some explanation in the case of an error.</p>

</dd>
</dl>

<h2 id="$q-=-QUOTE"><a class="permalink" href="./IPC::Cmd.html#$q-=-QUOTE">#</a><a id="q-QUOTE"></a>$q = QUOTE</h2>

<p>Returns the character used for quoting strings on this platform. This is usually a <code>&#39;</code> (single quote) on most systems, but some systems use different quotes. For example, <code>Win32</code> uses <code>&quot;</code> (double quote).</p>

<p>You can use it as follows:</p>

<pre><code>use IPC::Cmd qw[run QUOTE];
my $cmd = q[echo ] . QUOTE . q[foo bar] . QUOTE;</code></pre>

<p>This makes sure that <code>foo bar</code> is treated as a string, rather than two separate arguments to the <code>echo</code> function.</p>

<h1 id="HOW-IT-WORKS"><a class="permalink" href="./IPC::Cmd.html#HOW-IT-WORKS">#</a><a id="HOW"></a>HOW IT WORKS</h1>

<p><code>run</code> will try to execute your command using the following logic:</p>

<ul>

<li><p>If you have <code>IPC::Run</code> installed, and the variable <code>$IPC::Cmd::USE_IPC_RUN</code> is set to true (See the <a href="./IPC::Cmd.html#Global-Variables">&quot;Global Variables&quot;</a> section) use that to execute the command. You will have the full output available in buffers, interactive commands are sure to work and you are guaranteed to have your verbosity settings honored cleanly.</p>

</li>
<li><p>Otherwise, if the variable <code>$IPC::Cmd::USE_IPC_OPEN3</code> is set to true (See the <a href="./IPC::Cmd.html#Global-Variables">&quot;Global Variables&quot;</a> section), try to execute the command using <a href="./IPC::Open3.html">IPC::Open3</a>. Buffers will be available on all platforms, interactive commands will still execute cleanly, and also your verbosity settings will be adhered to nicely;</p>

</li>
<li><p>Otherwise, if you have the <code>verbose</code> argument set to true, we fall back to a simple <code>system()</code> call. We cannot capture any buffers, but interactive commands will still work.</p>

</li>
<li><p>Otherwise we will try and temporarily redirect STDERR and STDOUT, do a <code>system()</code> call with your command and then re-open STDERR and STDOUT. This is the method of last resort and will still allow you to execute your commands cleanly. However, no buffers will be available.</p>

</li>
</ul>

<h1 id="Global-Variables"><a class="permalink" href="./IPC::Cmd.html#Global-Variables">#</a><a id="Global"></a>Global Variables</h1>

<p>The behaviour of IPC::Cmd can be altered by changing the following global variables:</p>

<h2 id="$IPC::Cmd::VERBOSE"><a class="permalink" href="./IPC::Cmd.html#$IPC::Cmd::VERBOSE">#</a><a id="IPC::Cmd::VERBOSE"></a>$IPC::Cmd::VERBOSE</h2>

<p>This controls whether IPC::Cmd will print any output from the commands to the screen or not. The default is 0.</p>

<h2 id="$IPC::Cmd::USE_IPC_RUN"><a class="permalink" href="./IPC::Cmd.html#$IPC::Cmd::USE_IPC_RUN">#</a><a id="IPC::Cmd::USE_IPC_RUN"></a>$IPC::Cmd::USE_IPC_RUN</h2>

<p>This variable controls whether IPC::Cmd will try to use <a href="./IPC::Run.html">IPC::Run</a> when available and suitable.</p>

<h2 id="$IPC::Cmd::USE_IPC_OPEN3"><a class="permalink" href="./IPC::Cmd.html#$IPC::Cmd::USE_IPC_OPEN3">#</a><a id="IPC::Cmd::USE_IPC_OPEN3"></a>$IPC::Cmd::USE_IPC_OPEN3</h2>

<p>This variable controls whether IPC::Cmd will try to use <a href="./IPC::Open3.html">IPC::Open3</a> when available and suitable. Defaults to true.</p>

<h2 id="$IPC::Cmd::WARN"><a class="permalink" href="./IPC::Cmd.html#$IPC::Cmd::WARN">#</a><a id="IPC::Cmd::WARN"></a>$IPC::Cmd::WARN</h2>

<p>This variable controls whether run-time warnings should be issued, like the failure to load an <code>IPC::*</code> module you explicitly requested.</p>

<p>Defaults to true. Turn this off at your own risk.</p>

<h2 id="$IPC::Cmd::INSTANCES"><a class="permalink" href="./IPC::Cmd.html#$IPC::Cmd::INSTANCES">#</a><a id="IPC::Cmd::INSTANCES"></a>$IPC::Cmd::INSTANCES</h2>

<p>This variable controls whether <code>can_run</code> will return all instances of the binary it finds in the <code>PATH</code> when called in a list context.</p>

<p>Defaults to false, set to true to enable the described behaviour.</p>

<h2 id="$IPC::Cmd::ALLOW_NULL_ARGS"><a class="permalink" href="./IPC::Cmd.html#$IPC::Cmd::ALLOW_NULL_ARGS">#</a><a id="IPC::Cmd::ALLOW_NULL_ARGS"></a>$IPC::Cmd::ALLOW_NULL_ARGS</h2>

<p>This variable controls whether <code>run</code> will remove any empty/null arguments it finds in command arguments.</p>

<p>Defaults to false, so it will remove null arguments. Set to true to allow them.</p>

<h1 id="Caveats"><a class="permalink" href="./IPC::Cmd.html#Caveats">#</a>Caveats</h1>

<dl>

<dt id="Whitespace-and-IPC::Open3-/-system()"><a class="permalink" href="./IPC::Cmd.html#Whitespace-and-IPC::Open3-/-system()">#</a><a id="Whitespace"></a><a id="Whitespace-and-IPC::Open3-system"></a>Whitespace and IPC::Open3 / system()</dt>
<dd>

<p>When using <code>IPC::Open3</code> or <code>system</code>, if you provide a string as the <code>command</code> argument, it is assumed to be appropriately escaped. You can use the <code>QUOTE</code> constant to use as a portable quote character (see above). However, if you provide an array reference, special rules apply:</p>

<p>If your command contains <b>special characters</b> (&lt; &gt; | &amp;), it will be internally stringified before executing the command, to avoid that these special characters are escaped and passed as arguments instead of retaining their special meaning.</p>

<p>However, if the command contained arguments that contained whitespace, stringifying the command would lose the significance of the whitespace. Therefore, <code>IPC::Cmd</code> will quote any arguments containing whitespace in your command if the command is passed as an arrayref and contains special characters.</p>

</dd>
<dt id="Whitespace-and-IPC::Run"><a class="permalink" href="./IPC::Cmd.html#Whitespace-and-IPC::Run">#</a><a id="Whitespace1"></a>Whitespace and IPC::Run</dt>
<dd>

<p>When using <code>IPC::Run</code>, if you provide a string as the <code>command</code> argument, the string will be split on whitespace to determine the individual elements of your command. Although this will usually just Do What You Mean, it may break if you have files or commands with whitespace in them.</p>

<p>If you do not wish this to happen, you should provide an array reference, where all parts of your command are already separated out. Note however, if there are extra or spurious whitespaces in these parts, the parser or underlying code may not interpret it correctly, and cause an error.</p>

<p>Example: The following code</p>

<pre><code class="plaintext">gzip -cdf foo.tar.gz | tar -xf -</code></pre>

<p>should either be passed as</p>

<pre><code class="plaintext">&quot;gzip -cdf foo.tar.gz | tar -xf -&quot;</code></pre>

<p>or as</p>

<pre><code class="plaintext">[&#39;gzip&#39;, &#39;-cdf&#39;, &#39;foo.tar.gz&#39;, &#39;|&#39;, &#39;tar&#39;, &#39;-xf&#39;, &#39;-&#39;]</code></pre>

<p>But take care not to pass it as, for example</p>

<pre><code class="plaintext">[&#39;gzip -cdf foo.tar.gz&#39;, &#39;|&#39;, &#39;tar -xf -&#39;]</code></pre>

<p>Since this will lead to issues as described above.</p>

</dd>
<dt id="IO-Redirect"><a class="permalink" href="./IPC::Cmd.html#IO-Redirect">#</a><a id="IO"></a>IO Redirect</dt>
<dd>

<p>Currently it is too complicated to parse your command for IO redirections. For capturing STDOUT or STDERR there is a work around however, since you can just inspect your buffers for the contents.</p>

</dd>
<dt id="Interleaving-STDOUT/STDERR"><a class="permalink" href="./IPC::Cmd.html#Interleaving-STDOUT/STDERR">#</a><a id="Interleaving"></a><a id="Interleaving-STDOUT-STDERR"></a>Interleaving STDOUT/STDERR</dt>
<dd>

<p>Neither IPC::Run nor IPC::Open3 can interleave STDOUT and STDERR. For short bursts of output from a program, e.g. this sample,</p>

<pre><code>for ( 1..4 ) {
    $_ % 2 ? print STDOUT $_ : print STDERR $_;
}</code></pre>

<p>IPC::[Run|Open3] will first read all of STDOUT, then all of STDERR, meaning the output looks like &#39;13&#39; on STDOUT and &#39;24&#39; on STDERR, instead of</p>

<pre><code class="plaintext">1
2
3
4</code></pre>

<p>This has been recorded in <a href="https://perldoc.perl.org/5.35.0/rt.cpan.org">rt.cpan.org</a> as bug #37532: Unable to interleave STDOUT and STDERR.</p>

</dd>
</dl>

<h1 id="See-Also"><a class="permalink" href="./IPC::Cmd.html#See-Also">#</a><a id="See"></a>See Also</h1>

<p><a href="./IPC::Run.html">IPC::Run</a>, <a href="./IPC::Open3.html">IPC::Open3</a></p>

<h1 id="ACKNOWLEDGEMENTS"><a class="permalink" href="./IPC::Cmd.html#ACKNOWLEDGEMENTS">#</a>ACKNOWLEDGEMENTS</h1>

<p>Thanks to James Mastros and Martijn van der Streek for their help in getting <a href="./IPC::Open3.html">IPC::Open3</a> to behave nicely.</p>

<p>Thanks to Petya Kohts for the <code>run_forked</code> code.</p>

<h1 id="BUG-REPORTS"><a class="permalink" href="./IPC::Cmd.html#BUG-REPORTS">#</a><a id="BUG"></a>BUG REPORTS</h1>

<p>Please report bugs or other issues to &lt;bug-ipc-cmd@rt.cpan.org&gt;.</p>

<h1 id="AUTHOR"><a class="permalink" href="./IPC::Cmd.html#AUTHOR">#</a>AUTHOR</h1>

<p>Original author: Jos Boumans &lt;kane@cpan.org&gt;. Current maintainer: Chris Williams &lt;bingos@cpan.org&gt;.</p>

<h1 id="COPYRIGHT"><a class="permalink" href="./IPC::Cmd.html#COPYRIGHT">#</a>COPYRIGHT</h1>

<p>This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
